package com.niit.az;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import java.util.Timer;
import java.util.TimerTask;

public class CourseManage extends AppCompatActivity {

    TextView result;
    CheckBox english,math,Android,data;
    Button btnOtherCourese;
    BottomFrag2 fragment = new BottomFrag2();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_manage);

        result = findViewById(R.id.result);
        english=findViewById(R.id.ck_english);
        math=findViewById(R.id.ck_math);
        Android=findViewById(R.id.ck_Android);
        data=findViewById(R.id.ck_data);
        btnOtherCourese = (Button) findViewById(R.id.btn_other_course);

        CheckedChanged checkedChanged=new CheckedChanged();
        english.setOnCheckedChangeListener(checkedChanged);
        math.setOnCheckedChangeListener(checkedChanged);
        Android.setOnCheckedChangeListener(checkedChanged);
        data.setOnCheckedChangeListener(checkedChanged);

        btnOtherCourese.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                transaction.replace(R.id.bottom_layout, fragment);
                transaction.commit();
                Timer timer = new Timer();
                TimerTask timerTask = new TimerTask() {
                    @Override
                    public void run() {
                        Intent myIntent=new Intent(CourseManage.this,NextCourse.class);
                        startActivity(myIntent);
                    }
                };
                timer.schedule(timerTask,2000);
            }

        });
    }
    class CheckedChanged implements CompoundButton.OnCheckedChangeListener{
        String course;
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
            course="";
            result.setText("");
            if(english.isChecked()){
                //        course=course+""+english.getText().toString();
                course = english.getText().toString();
            }
            if(math.isChecked()){
                course+=" "+math.getText().toString();
            }
            if(Android.isChecked()){
                course+=" "+Android.getText().toString();
            }
            if(data.isChecked()){
                course+=" "+data.getText().toString();
            }
            result.setText(course);
        }
    }
}
